<?php

require_once 'Mobitv/Admin/Action.php';

class DeleteAction extends Mobitv_Admin_Action {

    public function execute() {
        $this->checkPermission();

        if (!isset($_SESSION['viewall']))
            $this->gotoUrl('/user');

        if (!$_SESSION['viewall']) {
            $userId = $_SESSION['userid'];
            $goto = '/myvideo';
        } else {
            $userId = 0;
            $goto = '/video';
        }

        $this->setOption('output', FALSE);

        $list = array();
        $ids = (isset($_GET['id'])) ? $_GET['id'] : 0;
        $token = (isset($_GET['t'])) ? $_GET['t'] : null;

        if ($ids && $token == $_SESSION['token']) {
            $ids = explode(",", $ids);

            foreach ($ids AS $id) {
                $list[] = intval($id);
            }

            $videoDao = Vega_Dao::factory('Mobitv_Admin_Video');
            if (!$videoDao->deleteFromList($list, $userId)) {
                $this->gotoUrl($goto, 'Lỗi hệ thống!');
            } else {
                $this->updateLogAdmin($_SESSION['userid'], 'video', $_GET['id'], 'delete');
                $this->gotoUrl($goto, 'Xóa thành công!');
            }
        }

        $this->gotoUrl($goto, 'Yêu cầu không hợp lệ!');
    }

}